package com.visikard.item;

import org.json.JSONObject;

import com.visikard.widget.expandedlistview.BaseExpandableListItem;

import android.os.Parcel;
import android.os.Parcelable;

public class ItemTransactionGiftKard extends BaseExpandableListItem implements Parcelable {	

	String kardName;
	long userId;
    long merchantId;
    long dateTime;
    int isGiftSpecial;
    long purchaseTransactionId;
    String redemptionValue;
    String kardImage;
    long redeemedTransactionId;
    String remainingValue;
    String dateTimeWithTimezone;
    int iscoupon;
    String imageGiftKard;
    String username;
    String paymentMethod;
    String redeemptionCode;
    String originalAmount;
    String address;
    int redeemedCount;
    String kardNumber;
    String status;
    int requiredBuy;
    int redeemTime;
    
    //UI
    public static final int DEFAULT_COLLAPSED_HEIGHT = 161;
    
    public ItemTransactionGiftKard() {
    	super(DEFAULT_COLLAPSED_HEIGHT);
    }
    
    public ItemTransactionGiftKard( JSONObject job ) {
    	super(DEFAULT_COLLAPSED_HEIGHT);
    	
    	if(job == null)
    		return;
    		
    	kardName = job.optString("kardName", "");
        if(kardName == null || kardName.equals("null"))
        	kardName = "";
        
    	userId = job.optLong("userId", -1);
    	
        merchantId = job.optLong("merchantId", -1);
        
        dateTime = job.optLong("dateTime", 0);
        
        isGiftSpecial = job.optInt("isGiftSpecial", 0);
        
        purchaseTransactionId = job.optLong("purchaseTransactionId", -1);
        
        redemptionValue = job.optString("redemptionValue", "0.00");
        if(redemptionValue == null || redemptionValue.equals("null"))
        	redemptionValue = "0.00";
        
        kardImage = job.optString("kardImage", "");
        if(kardImage == null || kardImage.equals("null"))
        	kardImage = "";
        
        redeemedTransactionId = job.optLong("redeemedTransactionId", -1);
        
        remainingValue = job.optString("remainingValue", "0.00");
        if(remainingValue == null || remainingValue.equals("null"))
        	remainingValue = "0.00";
        
        dateTimeWithTimezone = job.optString("dateTimeWithTimezone", "");
        if(dateTimeWithTimezone == null || dateTimeWithTimezone.equals("null"))
        	dateTimeWithTimezone = "";
        
        iscoupon = job.optInt("iscoupon", 0);
        
        imageGiftKard = job.optString("imageGiftKard", "");
        if(imageGiftKard == null || imageGiftKard.equals("null"))
        	imageGiftKard = "";
        
        username = job.optString("username", "");
        if(username == null || username.equals("null"))
        	username = "";
        
        paymentMethod = job.optString("paymentMethod", "");
        if(paymentMethod == null || paymentMethod.equals("null"))
        	paymentMethod = "";
        
        redeemptionCode = job.optString("redeemCode", "");
        if(redeemptionCode == null || redeemptionCode.equals("null"))
        	redeemptionCode = "";
        
        originalAmount = job.optString("originalAmount", "0.00");
        if(originalAmount == null || originalAmount.equals("null"))
        	originalAmount = "0.00";
        
        address = job.optString("address", "");
        if(address == null || address.equals("null"))
        	address = "";
        
        redeemedCount = job.optInt("redeemedCount", 0);
        
        kardNumber = job.optString("kardNumber", "");
        if(kardNumber == null || kardNumber.equals("null"))
        	kardNumber = "";
        
        status = job.optString("status", "");
        if(status == null || status.equals("null"))
        	status = "";
        
        //new api returns
        requiredBuy = job.optInt("requireBuy", 0);
        redeemTime = job.optInt("redeemTime", 0);
    }
    
  //constructor used for pacerlable
	protected ItemTransactionGiftKard(Parcel src){
		super(DEFAULT_COLLAPSED_HEIGHT);
		
		kardName = src.readString();
		userId = src.readLong();
		merchantId = src.readLong();
		dateTime = src.readLong();
		isGiftSpecial = src.readInt();
		purchaseTransactionId = src.readLong();
		redemptionValue = src.readString();
		kardImage = src.readString();
		redeemedTransactionId = src.readLong();
		remainingValue = src.readString();
		dateTimeWithTimezone = src.readString();
		iscoupon = src.readInt();
		imageGiftKard = src.readString();
		username = src.readString();
		paymentMethod = src.readString();
		redeemptionCode = src.readString();
		originalAmount = src.readString();
		address = src.readString();
		redeemedCount = src.readInt();
	    kardNumber = src.readString();
	    status = src.readString();
	    requiredBuy = src.readInt();
	    redeemTime = src.readInt();
	}

	@Override
	public void writeToParcel(Parcel target, int arg1) {
	    target.writeString(kardName);
		target.writeLong(userId);
		target.writeLong(merchantId);
		target.writeLong(dateTime);
		target.writeInt(isGiftSpecial);
		target.writeLong(purchaseTransactionId);
		target.writeString(redemptionValue);
		target.writeString(kardImage);
		target.writeLong(redeemedTransactionId);
		target.writeString(remainingValue);
		target.writeString(dateTimeWithTimezone);
		target.writeInt(iscoupon);
		target.writeString(imageGiftKard);
		target.writeString(username);
		target.writeString(paymentMethod);
		target.writeString(redeemptionCode);
		target.writeString(originalAmount);
		target.writeString(address);
		target.writeInt(redeemedCount);
		target.writeString(kardNumber);
		target.writeString(status);
		target.writeInt(redeemTime);
		target.writeInt(requiredBuy);
	}
	
	public static final Parcelable.Creator<ItemTransactionGiftKard> CREATOR = new Creator<ItemTransactionGiftKard>() {
		@Override
		public ItemTransactionGiftKard createFromParcel(Parcel source) {
			return new ItemTransactionGiftKard(source);
		}

		@Override
		public ItemTransactionGiftKard[] newArray(int size) {
			return new ItemTransactionGiftKard[size];
		}
	};

	public String getKardName() {
		return kardName;
	}

	public long getUserId() {
		return userId;
	}

	public long getMerchantId() {
		return merchantId;
	}

	public long getDateTime() {
		return dateTime;
	}

	public int getIsGiftSpecial() {
		return isGiftSpecial;
	}

	public long getPurchaseTransactionId() {
		return purchaseTransactionId;
	}

	public String getRedemptionValue() {
		return redemptionValue;
	}

	public String getKardImage() {
		return kardImage;
	}

	public long getRedeemedTransactionId() {
		return redeemedTransactionId;
	}

	public String getRemainingValue() {
		return remainingValue;
	}

	public String getDateTimeWithTimezone() {
		return dateTimeWithTimezone;
	}

	public int getIscoupon() {
		return iscoupon;
	}

	public String getImageGiftKard() {
		return imageGiftKard;
	}

	public String getUsername() {
		return username;
	}

	public String getPaymentMethod() {
		return paymentMethod;
	}

	public void setPaymentMethod(String paymentMethod) {
		this.paymentMethod = paymentMethod;
	}

	public String getRedeemptionCode() {
		return redeemptionCode;
	}
	
	public void setRedeemptionCode(String redeemptionCode) {
		this.redeemptionCode = redeemptionCode;
	}

	public String getOriginalAmount() {
		return originalAmount;
	}
	
	public double getOriginalAmountNumber() {
		try{
//			String strValue = purchase_value.split("$")[0];
			String strValue = originalAmount.substring(1, originalAmount.length());
			return Double.parseDouble(strValue);
		}catch(Exception e){
			return 0;
		}
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public int getRedeemedCount() {
		return redeemedCount;
	}

	public void setRedeemedCount(int redeemedCount) {
		this.redeemedCount = redeemedCount;
	}

	public String getKardNumber() {
		return kardNumber;
	}

	public void setKardNumber(String kardNumber) {
		this.kardNumber = kardNumber;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	@Override
	public int describeContents() {
		// TODO Auto-generated method stub
		return 0;
	}

	public int getRequiredBuy() {
		return requiredBuy;
	}

	public void setRequiredBuy(int requiredBuy) {
		this.requiredBuy = requiredBuy;
	}

	public int getRedeemTime() {
		return redeemTime;
	}

	public void setRedeemTime(int redeemTime) {
		this.redeemTime = redeemTime;
	}
}
